//
//  WaterDetailViewController.m
//  XDCommonApp
//
//  Created by wanglong8889@126.com on 14-3-11.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "WaterDetailViewController.h"
#import "XDHeader.h"
#import "UMSocial.h"
#import "LoginViewController.h"
#import "PersonSetViewController.h"
#import "WaterFLayout.h"
#import "WaterF.h"
#import "XDTools.h"
#import "SizeTableViewCell.h"
#import "WaterFlow.h"
#define KPICHEIGHT 150
@interface WaterDetailViewController ()

@end

@implementation WaterDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    //[footer free];
    //[header free];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.

    sizeOrder = @"1";
    hotOrder = @"1";
    page = 0;
    isHeaderRefresh = YES;
    isHaveMoreData = YES;
    
    dataArrary = [NSMutableArray arrayWithCapacity:3];
    sizeArrary = [NSMutableArray arrayWithCapacity:4];
    [sizeArrary addObject:@"全部尺寸"];
    
    if ([self.subID isEqualToString:@"000"]) {
        self.subID =@"";
    }
    if (![self.signal isEqualToString:@"0"]) {
        if ([self.signal isEqualToString:@"1"]) {
            if (self.artistName == nil||[self.artistName isEqualToString:@""]) {
                self.titleLabel.text = @"参展作品";
            }else{
                self.titleLabel.text = [NSString stringWithFormat:@"%@的作品",self.artistName];
            }
        }else{
            self.titleLabel.text = @"参展作品";
        }
       
    }else{
        if ([self.subID isEqualToString:@""]) {
            self.titleLabel.text = @"全部";
        }else{
             self.titleLabel.text = self.subID;
        }
       
    }
    
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.font = [UIFont systemFontOfSize:18];
    
    UILabel *lefTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(44, 13, 60, 18)];
    lefTitleLabel.text = self.classID;
    lefTitleLabel.backgroundColor = [UIColor clearColor];
    lefTitleLabel.textColor = [UIColor blackColor];
    lefTitleLabel.font = [UIFont systemFontOfSize:16];
    
    [self.navigationBarView addSubview:lefTitleLabel];
    
    UIImageView *selecBackView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,320, 39)];
    selecBackView.image = [UIImage imageNamed:@"selected_back"];
    selecBackView.userInteractionEnabled = YES;
    [self.contentView addSubview:selecBackView];
    
    
    UILabel *sizeLabel = [[UILabel alloc] initWithFrame:CGRectMake(17, 10, 60, 18)];
    sizeLabel.text = self.classID;
    sizeLabel.text = @"全部尺寸";
    sizeLabel.textColor = [UIColor grayColor];
    sizeLabel.backgroundColor = [UIColor clearColor];
    sizeLabel.font = [UIFont systemFontOfSize:14];
    
    
    UILabel *hotLabel = [[UILabel alloc] initWithFrame:CGRectMake(124, 10, 60, 18)];
    hotLabel.text = self.classID;
    hotLabel.text = @"热度排序";
    hotLabel.backgroundColor = [UIColor clearColor];
    hotLabel.textColor = [UIColor grayColor];
    hotLabel.font = [UIFont systemFontOfSize:14];
    
    artLabel = [[UILabel alloc] initWithFrame:CGRectMake(232, 10, 80, 18)];
    artLabel.text = self.classID;
    artLabel.textColor = [UIColor grayColor];
    artLabel.backgroundColor = [UIColor clearColor];
    artLabel.text = @"作品";
    artLabel.textAlignment = NSTextAlignmentCenter;
    artLabel.font = [UIFont systemFontOfSize:12.0];
    
    daoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(sizeLabel.frame.origin.x+sizeLabel.frame.size.width, 15, 9, 5)];
    daoImageView.image = [UIImage imageNamed:@"dao_sanjiao"];
    
    [selecBackView addSubview:daoImageView];
    
    daoImageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(hotLabel.frame.origin.x+hotLabel.frame.size.width, 15, 9, 5)];
    daoImageView2.image = [UIImage imageNamed:@"dao_sanjiao"];
    
    [selecBackView addSubview:daoImageView2];
    
    UIButton *sizeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sizeBtn.frame = CGRectMake(0, 0, 102, 38);
    [sizeBtn addTarget:self action:@selector(sizeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [selecBackView addSubview:sizeBtn];
    
    UIButton *hotBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    hotBtn.frame = CGRectMake(102, 0, 102, 38);
    [hotBtn addTarget:self action:@selector(hotBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [selecBackView addSubview:hotBtn];
    
    [selecBackView addSubview:sizeLabel];
    [selecBackView addSubview:hotLabel];
    [selecBackView addSubview:artLabel];
    
    if (![self.signal isEqualToString:@"0"]) {
        hhhh = 0.0;
        selecBackView.hidden = YES;
        lefTitleLabel.hidden = YES;
    }else{
        hhhh = 40.0;
        selecBackView.hidden = NO;
        lefTitleLabel.hidden = NO;
        
    }

//    [XDTools showProgress:self.contentView];
    [self initWaterFlowView];
    switch ([self.signal intValue]) {
        case 1:
            [self getArtistDatas];
            break;
        case 3:
            [self getActivityDatas];
            break;
        case 0:
            [self getDatas:0];
            break;
        case 2:
            [self getGalleryDatas];
            break;
        case 4:
            [self getOrgernizeDatas];
            break;
        default:
            break;
    }

    

    
  
    
//    [self performSelector:@selector(aa) withObject:nil afterDelay:1.0];
//    [self performSelector:@selector(initDatas) withObject:nil afterDelay:1.0];
//    [self performSelector:@selector(initWaterFlowView) withObject:nil afterDelay:1.0];
    //    [self initDatas];
    //    [self initWaterFlowView];
    //    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    //    btn.frame = CGRectMake(100, 100, 100, 100);
    //    [btn setTitle:@"share" forState:UIControlStateNormal];
    //    [btn addTarget:self action:@selector(shareClick) forControlEvents:UIControlEventTouchUpInside];
    //    btn.backgroundColor = [UIColor greenColor];
    //    [self.contentView addSubview:btn];
    
}
-(void)aa{
    [XDTools hideProgress:self.contentView];
}
//跳到设置界面
-(void)goToSetting{
    
    PersonSetViewController *perVC = [[PersonSetViewController alloc] init];
    [self.navigationController pushViewController:perVC animated:YES];
}
-(void)goLaun{
    LoginViewController *logVC = [[LoginViewController alloc] init];
    [self.navigationController pushViewController:logVC animated:YES];
}
-(void)shareClick
{
    DDLOG_CURRENT_METHOD;
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:UMAPPKEY
                                      shareText:SHARETITLE
                                     shareImage:[UIImage imageNamed:@"Icon"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToWechatSession,UMShareToWechatTimeline,nil]
                                       delegate:nil];
}



-(void)initWaterFlowView{
    
    WaterFLayout* flowLayout = [[WaterFLayout alloc]init];
    self.waterfall = [[WaterF alloc]initWithCollectionViewLayout:flowLayout];
//    self.waterfall.imagesArr = self.images;
//    self.waterfall.textsArr = self.texts;
    flowLayout.minimumColumnSpacing = -20.0;
    self.waterfall.sectionNum = 2;
    self.waterfall.imagewidth = 130;
    float artHeight;
    if ([self.signal intValue]!=0) {
        artLabel.hidden = YES;
        artHeight = 18.0;
    }
    self.waterfall.collectionView.frame = CGRectMake(5, hhhh-20, 320, self.contentView.frame.size.height-hhhh);
    [self.contentView addSubview:self.waterfall.view];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideview)];
    toumingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height)];
    toumingView.alpha = .7;
    toumingView.backgroundColor = [UIColor grayColor];
    toumingView.hidden = YES;
    [toumingView addGestureRecognizer:tap];
    [self.view addSubview:toumingView];
    
    float height;
    if (IOS7) {
        height = 102;
//        height = 112;
    }else{
        height = 80;
    }
    sizeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, height, 320, 280) style:UITableViewStylePlain];
    sizeTableView.delegate = self;
    sizeTableView.dataSource = self;
    sizeTableView.hidden = YES;
    [self.view addSubview:sizeTableView];
    
    cheader = [[MJRefreshHeaderView  alloc] init];
    cheader.delegate = self;
    cheader.scrollView= _waterfall.collectionView;
    
    cfooter = [[MJRefreshFooterView alloc] init];
    cfooter.delegate = self;
    cfooter.scrollView = _waterfall.collectionView;
    
}

//进入刷新就会调用
-(void)refreshViewBeginRefreshing:(MJRefreshBaseView *)refreshView
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] init];
    
    if (refreshView == cheader){
        isHeaderRefresh = YES;
    }else{
        isHeaderRefresh =NO;
    }
    
    switch ([self.signal intValue]) {
        case 1:
            [self getArtistDatas];
            break;
        case 3:
            [self getActivityDatas];
            break;
        case 0:
            [self getDatas:0];
            break;
        case 2:
            [self getGalleryDatas];
            break;
        case 4:
            [self getOrgernizeDatas];
            break;
        default:
            break;
    }
    
//    [dict setObject:@"一页面" forKey:@"页面"];
//    [NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(getNewData:) userInfo:dict repeats:NO];
}

//-(void)getNewData:(NSTimer *)timer
//{
//    NSString * str = [[timer userInfo] objectForKey:@"页面"];
//    
//    [self getDatas];
//}

-(void)refreshViewEndRefreshing:(MJRefreshBaseView *)refreshView
{
    if (refreshView == cfooter){
        
        //这里还要判断一下是不是加载没数据，如果没有数据，就执行下面两行，这样就能解决上拉箭头不下了的bug
        if (!isHaveMoreData){
            CGPoint point = _waterfall.collectionView.contentOffset;
            _waterfall.collectionView.contentOffset = CGPointMake(0, point.y-cfooter.frame.size.height);
            DDLOG(@"point = %f,point = %f",point.x,point.y);
        }
    }else{
    
    }
}
///

//弹出尺寸列表
-(void)sizeBtnAction{
    if ([sizeOrder intValue] == 1) {
        sizeOrder = @"0";
        daoImageView.image = [UIImage imageNamed:@"shaixuan_up"];
    }else{
        sizeOrder = @"1";
        daoImageView.image = [UIImage imageNamed:@"shaixuan_down"];
    }
    [dataArrary removeAllObjects];
    [self getDatas:1];
//    sizeTableView.hidden = NO;
//    toumingView.hidden = NO;
}

-(void)hotBtnAction{
    if ([hotOrder intValue] == 1) {
        hotOrder = @"0";
        daoImageView2.image = [UIImage imageNamed:@"shaixuan_up"];
    }else{
        hotOrder = @"1";
        daoImageView2.image = [UIImage imageNamed:@"shaixuan_down"];
    }
    [dataArrary removeAllObjects];
    [self getDatas:1];
}
-(void)getOrgernizeDatas{
    if ([XDTools NetworkReachable]){
        isHaveMoreData = YES;
        int oldPage = page;
        if (isHeaderRefresh){
            page = 0;
        }else{
            page++;
        }
        DDLOG(@"************************page = %d",page);
        NSString * pageStr = [NSString stringWithFormat:@"%d",page];
        NSString *body = [NSString stringWithFormat:@" <ActivityArtworkListByOrganizationId xmlns=\"http://tempuri.org/\">"
                          "<organizationId>%@</organizationId>"
                          "<pageIndex>%@</pageIndex>"
                          "<limit>%@</limit>"
                          "</ActivityArtworkListByOrganizationId>",self.orgernizeId,pageStr,@"10"];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:WORKLISTBYORGERNIZATIONID];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                if(page == 0){
                    [dataArrary removeAllObjects];
                }
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                DDLOG(@"respodic = %@",responseDict);
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    NSArray *arr = [responseDict objectForKey:@"workList"];
                    for (int i=0; i<arr.count; i++) {
                        NSDictionary *dic = [arr objectAtIndex:i];
                        WaterFlow *water = [[WaterFlow alloc] initWithDic:dic];
                        [dataArrary addObject:water];
                        
                    }
                    
                    DDLOG(@"dataarrary = %@",dataArrary);
                    self.waterfall.imagesArr = dataArrary;
                    if (dataArrary.count == 0) {
                        page = oldPage;
                        [XDTools showTips:@"暂无数据" toView:self.contentView];
                    }else{
                        if([[responseDict objectForKey:@"workList"] count]==0){
                            [XDTools showTips:@"没有更多数据" toView:self.contentView];
                            isHaveMoreData =NO;
                        }
                    }
                    
                    [self.waterfall.collectionView reloadData];
                    
                    [cfooter endRefreshing];
                    [cheader endRefreshing];
                    
                    
                }else{
                    [XDTools showTips:@"暂无数据" toView:self.contentView];
                }
            }
        }];
        
        [request setFailedBlock:^{
            page = oldPage;
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
}
-(void)getDatas:(int)paiXu{
    if ([XDTools NetworkReachable]){
        isHaveMoreData = YES;
        int oldPage = page;
        if (isHeaderRefresh){
            page = 0;
        }else{
            if (paiXu == 0) {
                page++;
            }
            
        }
        DDLOG(@"getDatas************************page = %d",page);
        NSString * pageStr = [NSString stringWithFormat:@"%d",page];
        NSString *body = [NSString stringWithFormat:@" <WorkListById xmlns=\"http://tempuri.org/\">"
                          "<class>%@</class>"
                          "<theme>%@</theme>"
                          "<sizeOrderType>%@</sizeOrderType>"
                          "<hotOrderType>%@</hotOrderType>"
                          "<pageIndex>%@</pageIndex>"
                          "<limit>%@</limit>"
                          "</WorkListById>",self.classID,self.subID,sizeOrder,hotOrder,pageStr,@"10"];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:WORKLISTBYID];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                if(page == 0){
                    [dataArrary removeAllObjects];
                }
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                DDLOG(@"respodic = %@",responseDict);
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    artLabel.text = [NSString stringWithFormat:@"%d件作品",[[responseDict objectForKey:@"totalCount"] intValue]];
                    NSArray *arr = [responseDict objectForKey:@"workList"];
                    for (int i=0; i<arr.count; i++) {
                        NSDictionary *dic = [arr objectAtIndex:i];
                        WaterFlow *water = [[WaterFlow alloc] initWithDic:dic];
                        [dataArrary addObject:water];
                        
                    }
                    DDLOG(@"dataarrary = %@",dataArrary);
                    self.waterfall.imagesArr = dataArrary;
                    if (dataArrary.count == 0) {
                        page = oldPage;
                        [XDTools showTips:@"暂无数据" toView:self.contentView];
                    }else{
                        if([[responseDict objectForKey:@"workList"] count]==0){
                            [XDTools showTips:@"没有更多数据" toView:self.contentView];
                            isHaveMoreData =NO;
                        }
                    }
                    
                    [self.waterfall.collectionView reloadData];
                    
                    [cfooter endRefreshing];
                    [cheader endRefreshing];


                }else{
                    page = oldPage;
                    [XDTools showTips:@"暂无数据" toView:self.contentView];
                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
}
-(void)getActivityDatas{
    if ([XDTools NetworkReachable]){
        isHaveMoreData = YES;
        int oldPage = page;
        if (isHeaderRefresh){
            page = 0;
        }else{
            page++;
        }
        DDLOG(@"************************page = %d",page);
        NSString * pageStr = [NSString stringWithFormat:@"%d",page];
        NSString *body = [NSString stringWithFormat:@" <GetArtworkListByActivityId xmlns=\"http://tempuri.org/\">"
                          "<activityId>%@</activityId>"
                          "<pageIndex>%@</pageIndex>"
                          "<limit>%@</limit>"
                          "</GetArtworkListByActivityId>",self.activityId,pageStr,@"10"];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:GETARTWORKLISTBYACTIVITYID];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            //DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                if(page == 0){
                    [dataArrary removeAllObjects];
                }
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                DDLOG(@"respodic = %@",responseDict);
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    NSArray *arr = [responseDict objectForKey:@"workList"];
                    for (int i=0; i<arr.count; i++) {
                        NSDictionary *dic = [arr objectAtIndex:i];
                        WaterFlow *water = [[WaterFlow alloc] initWithDic:dic];
                        [dataArrary addObject:water];
                        
                    }
                
                    DDLOG(@"dataarrary = %@",dataArrary);
                    self.waterfall.imagesArr = dataArrary;
                    if (dataArrary.count == 0) {
                        page = oldPage;
                        [XDTools showTips:@"暂无数据" toView:self.contentView];
                    }else{
                        if([[responseDict objectForKey:@"workList"] count]==0){
                            [XDTools showTips:@"没有更多数据" toView:self.contentView];
                            isHaveMoreData =NO;
                        }
                    }
                    
                    [self.waterfall.collectionView reloadData];
                    
                    [cfooter endRefreshing];
                    [cheader endRefreshing];
                    
                    
                }else{
                    [XDTools showTips:@"暂无数据" toView:self.contentView];
                }
            }
        }];
        
        [request setFailedBlock:^{
            page = oldPage;
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
}

-(void)getArtistDatas{
    if ([XDTools NetworkReachable]){
        isHaveMoreData = YES;
        int oldPage = page;
        if (isHeaderRefresh){
            page = 0;
        }else{
            page++;
        }
        NSString *body = [NSString stringWithFormat:@" <GetArtworkListByArtistId xmlns=\"http://tempuri.org/\">"
                          "<id>%@</id>"
                          "<pageidx>%@</pageidx>"
                          "<limit>%@</limit>"
                          "</GetArtworkListByArtistId>",self.artistId,[NSString stringWithFormat:@"%d",page],@"10"];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:GETARTWORKLISTBYARTISTID];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                if(page == 0){
                    [dataArrary removeAllObjects];
                }
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                DDLOG(@"respodic = %@",responseDict);
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    NSArray *arr = [responseDict objectForKey:@"workList"];
                    for (int i=0; i<arr.count; i++) {
                        NSDictionary *dic = [arr objectAtIndex:i];
                        WaterFlow *water = [[WaterFlow alloc] initWithDic:dic];
                        [dataArrary addObject:water];
                        
                    }
                    
                    DDLOG(@"dataarrary = %@",dataArrary);
                    self.waterfall.imagesArr = dataArrary;
                    if (dataArrary.count == 0) {
                        page = oldPage;
                        [XDTools showTips:@"暂无数据" toView:self.contentView];
                    }else{
                        if([[responseDict objectForKey:@"workList"] count]==0){
                            [XDTools showTips:@"没有更多数据" toView:self.contentView];
                            isHaveMoreData =NO;
                        }
                    }
                    
                    [self.waterfall.collectionView reloadData];
                    
                    [cfooter endRefreshing];
                    [cheader endRefreshing];
                    
                }else{
                    [XDTools showTips:@"暂无数据" toView:self.contentView];
                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
}

-(void)getGalleryDatas{
    if ([XDTools NetworkReachable]){
        isHaveMoreData = YES;
        int oldPage = page;
        if (isHeaderRefresh){
            page = 0;
        }else{
            page++;
        }
        NSString *body = [NSString stringWithFormat:@" <GetArtworkListByGallryId xmlns=\"http://tempuri.org/\">"
                          "<id>%@</id>"
                          "<pageidx>%@</pageidx>"
                          "<limit>%@</limit>"
                          "</GetArtworkListByGallryId>",self.galleryId,[NSString stringWithFormat:@"%d",page],@"1"];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:GETARTWORKLISTBYGALLERYID];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                if(page == 0){
                    [dataArrary removeAllObjects];
                }
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                DDLOG(@"respodic = %@",responseDict);
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    NSArray *arr = [responseDict objectForKey:@"workList"];
                    for (int i=0; i<arr.count; i++) {
                        NSDictionary *dic = [arr objectAtIndex:i];
                        WaterFlow *water = [[WaterFlow alloc] initWithDic:dic];
                        [dataArrary addObject:water];
                        
                    }
                    DDLOG(@"dataarrary = %@",dataArrary);
                    self.waterfall.imagesArr = dataArrary;
                    if (dataArrary.count == 0) {
                        page = oldPage;
                        [XDTools showTips:@"暂无数据" toView:self.contentView];
                    }else{
                        if([[responseDict objectForKey:@"workList"] count]==0){
                            [XDTools showTips:@"没有更多数据" toView:self.contentView];
                            isHaveMoreData =NO;
                        }
                    }
                    
                    [self.waterfall.collectionView reloadData];
                    
                }else{
                    [XDTools showTips:@"暂无数据" toView:self.contentView];
                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
}
#pragma mark  ========================UITableView delegate==========================
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    return 40;
    return 44;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  
    return 10;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellName = @"cell";
    SizeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
    if (!cell) {
        cell = [[SizeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
    }

    if (indexPath.row == 0) {
        cell.contentLabel.text = @"全部尺寸";
        cell.contentLabel.font = [UIFont systemFontOfSize:15.0];
        cell.backgroundColor = [UIColor whiteColor];
    }else{
        cell.contentLabel.text = @"40×50cm";
        cell.backgroundColor = RGBA(239, 239, 239, 1.0);
        
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    [self hideview];
}

-(void)hideview{
    sizeTableView.hidden = YES;
    toumingView.hidden = YES;
}

- (void)backPrePage
{
    DDLOG_CURRENT_METHOD;
//    self.waterfall.collectionView.delegate = nil;
    [cheader free];
    [cfooter free];
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
